package com.jxnu.escms.Service.UserService.impl;

import com.jxnu.escms.Service.UserService.EmailService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Random;

@Service
public class EmailServiceImpl implements EmailService {

    @Resource
    private JavaMailSender javaMailSender;

    //    @Value("escms_ylhczx@163.com")
    @Value("${spring.mail.username}")
    private String from;

    @Override
    public String sendEmail(String email, String name) {
        Random random = new Random();
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(from);
        message.setTo(email);
        message.setSubject("EMCMS疫情社区管理系统邮箱验证");
        message.setText("亲爱的" + name + "先生/女士\n" + "   您好：\n");
        String verCode = String.valueOf(random.nextDouble()*1e6).split("\\.")[0];
        message.setText("\t您的验证码是：" + verCode + ", 请在5分钟内完成验证。");
        String VerCode = " ";
        javaMailSender.send(message);
        return verCode;
    }
}
